/*
 *@Author: 张楚
 *@Date: 2022-02-09 17:05:52
 *@Description: 优雅的dialog
*/

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:totaldemo/config/init_config.dart';
import 'package:totaldemo/practice/smartDemo/DropdownButton.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

class SmartDialogPage extends StatefulWidget {
  const SmartDialogPage({Key key}) : super(key: key);
  @override
  _SmartDialogPageState createState() => _SmartDialogPageState();
}

class _SmartDialogPageState extends State<SmartDialogPage> {
  List<MenuBean> smartList = [];

  var list = ['小呆呆', '小菲菲', '小猪猪'];

  @override
  void initState() {
    super.initState();
    _initList();
  }

  void _initList() {
    smartList.add(MenuBean(
        title: 'DropdownButton',
        onclick: () {
          SmartDialogUntils.attachImitate();
        }));
  }

  @override
  Widget build(BuildContext context) {
    List<int> nums = [3, 2, 4];
    int target = 6;

    twoSum(List nums, int target) {
      int len = nums.length;
      List newList = [];
      try {
        for (var i = 0; i < len; i++) {
          for (var j = i + 1; j < len; j++) {
            if (nums[i] + nums[j] == target) {
              newList.addAll([i, j]);
              print(newList);
              return;
            }
          }
        }
      } catch (e) {
        print(e);
      }
    }

    return Scaffold(
      appBar: AppBar(
        title: Text('优雅的dialog'),
      ),
      body: Column(
        children: [
          Row(
            children: [
              TextButton(
                  onPressed: () => twoSum(nums, target),
                  // SmartDialog.showAttach(
                  //       targetContext: Get.context,
                  //       isPenetrateTemp: true,
                  //       widget: Container(
                  //         margin: EdgeInsets.all(10),
                  //         decoration: BoxDecoration(
                  //           boxShadow: [
                  //             BoxShadow(
                  //                 color: Colors.black12,
                  //                 blurRadius: 8,
                  //                 spreadRadius: 0.2)
                  //           ],
                  //         ),
                  //         child: Column(
                  //           children: List.generate(list.length, (index) {
                  //             return Material(
                  //               color: Colors.white,
                  //               child: InkWell(
                  //                 onTap: () {
                  //                   SmartDialog.dismiss();
                  //                   print(list[index]);
                  //                 },
                  //                 child: Container(
                  //                   height: 50,
                  //                   width: 100,
                  //                   alignment: Alignment.center,
                  //                   child: Text('${list[index]}'),
                  //                 ),
                  //               ),
                  //             );
                  //           }),
                  //         ),
                  //       ),
                  //     ),
                  child: Text('指标'))
            ],
          ),
          Wrap(
            children: List.generate(
                smartList.length,
                (index) => ElevatedButton(
                      onPressed: smartList[index].onclick,
                      child: Text(smartList[index].title),
                    )),
          ),
        ],
      ),
    );
  }

  imitateDropdownButton() {
    return Builder(builder: (context) {
      return Stack(children: [
        // dropdownButton(title: 'Attach'),
        Text('ads'),
        InkWell(
          onTap: () => imitateDialog(context),
          child: Container(height: 50, width: 140, color: Colors.transparent),
        )
      ]);
    });
  }

  imitateDialog(BuildContext context) {
    var list = ['小呆呆', '小菲菲', '小猪猪'];
    SmartDialog.showAttach(
      targetContext: context,
      isPenetrateTemp: true,
      widget: Container(
        margin: EdgeInsets.all(10),
        decoration: BoxDecoration(
          boxShadow: [
            BoxShadow(color: Colors.black12, blurRadius: 8, spreadRadius: 0.2)
          ],
        ),
        child: Column(
          children: List.generate(list.length, (index) {
            return Material(
              color: Colors.white,
              child: InkWell(
                onTap: () {
                  SmartDialog.dismiss();
                  print(list[index]);
                },
                child: Container(
                  height: 50,
                  width: 100,
                  alignment: Alignment.center,
                  child: Text('${list[index]}'),
                ),
              ),
            );
          }),
        ),
      ),
    );
  }
}
